package cn.jilian.admin.tool.service.support.formatters;

import java.text.SimpleDateFormat;

import cn.jilian.admin.tool.service.support.Formatter;

public class DateFormatter implements Formatter {
	
	private String format;
	
	public static DateFormatter TSFORMATTER=new DateFormatter("yyyy-MM-dd hh:mm:ss");
	
	public static DateFormatter DTFORMATTER=new DateFormatter("yyyy-MM-dd");
	
	public static DateFormatter TIMEFORMATTER=new DateFormatter("hh:mm:ss");
	
	public  DateFormatter(String format) {
		this.format=format;
	}

	@Override
	public String format(Object v) {
		if(v==null)return "null";
		String value=new SimpleDateFormat(format).format(v);
		return new StringBuilder("'").append(value).append("'").toString();
	}

	@Override
	public void append(StringBuilder sb, Object v) {
		if(v==null) {
			sb.append("null");
		}
		String value=new SimpleDateFormat(format).format(v);
		sb.append("'").append(value).append("'");
	}

}
